import { Color, IState, QUI_Container, QUI_Label, Vector2 } from "../common.js";
import { MainWin } from "../mainwin.js";
import { State_Main } from "./state_main.js";
import { State_MainMenu } from "./state_mainmenu.js";

export class State_Logo implements IState<MainWin> {
    container: QUI_Container;
    main: MainWin
    OnInit(mgr: MainWin): void {

        this.main = mgr;
        this.container = new QUI_Container();
        mgr.canvas.InsertChild(this.container);//插在前面
       
        
        {
            let label = new QUI_Label();
            label.localRect.SetAsFill();
            label.localRect.radioY1 = 0.5;
            label.localRect.radioY2 = 0.5;
            label.localRect.offsetY1 = -64;
            label.localRect.offsetY2 = -64;
            label.fontScale.X *= 4;
            label.fontScale.Y *= 4;
            this.container.AddChild(label);
            label.text = "MUD Engine V0.1"
        }
        {
            let label = new QUI_Label();
            label.localRect.SetAsFill();
            label.localRect.radioY1 = 0.5;
            label.localRect.radioY2 = 0.5;
            label.localRect.offsetY1 = 16;
            label.localRect.offsetY2 = 16;
            label.fontScale.X *= 2;
            label.fontScale.Y *= 2;
            label.localColor = new Color(1, 1, 0.3, 1);
            this.container.AddChild(label);
            label.text = "by lights"
        }
        
        this.timer = 0;
        this.container.localColor.A=0;
        this.container.OnUpdate(mgr.canvas,0);
    }
    timer: number = 0;
    OnUpdate(delta: number): void {
        this.timer += delta;
        let alpha = 0;
        if (this.timer < 1)
            alpha = this.timer;
        else if (this.timer < 2)
            alpha = 1;
        else {
            alpha = 1 - this.timer % 1.0;
        }
        this.container.localColor.A = alpha;
        if (this.timer > 3.0) {
            this.main.ChangeState(new State_MainMenu());
        }
    }
    OnExit(): void {
        this.main.canvas.RemoveChild(this.container);
    }
    OnResize(width: number, height: number): void {

    }
    OnKey(keycode: string, press: boolean): void {

    }
    OnPointAfterGUI(id: number, x: number, y: number, press: boolean, move: boolean): void {

    }
    OnWheelAfterGUI(dx: number, dy: number, dz: number): void {

    }

}